# -*- coding: UTF8 -*-
# Author: Sakurazaki
# (Aitor Martin. @arienai_ne - sakurazaki.setsunita@gmail.com)

import pygame

import gui as g, guielements as gs
import config as c
import imageloader as i
import paths

class GameState(object):

    def __init__(self):

        self.keep = True

        self.surface = pygame.surface.Surface((c.config['SCREEN_WIDTH'], c.config['SCREEN_HEIGHT']))
        self.rect = self.surface.get_rect()
        self.rect.center = (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/2)

        self.gui = g.GUI()
        self.font = pygame.font.SysFont('Arial', 16)

    def handleEvent(self, ev):
        self.gui.handleEvent(ev)

    def update(self, delta):
        pass

    def render(self):
        pass


class MainMenu(GameState):

    def __init__(self):

        super(MainMenu, self).__init__()

        self.logo = i.loadImage(paths.LOGO)
        self.lrect = self.logo.get_rect()
        self.lrect.center = (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/4)

        self.ver = self.font.render("SCSG v 0.0.1a", True, pygame.Color('White'))
        self.vrect = self.ver.get_rect()
        self.vrect.bottomleft = (0, c.config['SCREEN_HEIGHT'])

        self.gui.addGuiElement(gs.Button("New game", pygame.Color('White'), (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/2), self.start))
        self.gui.addGuiElement(gs.Button("Load Game", pygame.Color('White'), (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/2+80), self.load))
        self.gui.addGuiElement(gs.Button("Options", pygame.Color('White'), (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/2+160), self.options))
        self.gui.addGuiElement(gs.Button("Exit", pygame.Color('White'), (c.config['SCREEN_WIDTH']/2, c.config['SCREEN_HEIGHT']/2+240), self.ex))

    def update(self, delta):
        self.gui.update(delta)

    def render(self):
        self.gui.render()
        self.gui.draw(self.surface)
        self.surface.blit(self.logo, self.lrect)
        self.surface.blit(self.ver, self.vrect)
        
    def start(self):
        print "Clicked Start!"

    def load(self):
        print "Clicked Load!"

    def options(self):
        print "Clicked Options!"

    def ex(self):
        self.keep = False
